PAIRS = '/netflix/download/qualifying.txt'
RATINGS = '/netflix/grand_prize/judging.txt'
QUIZ = 0
TEST = 1
BOTH = 2

class QuizTest(object):
  def __init__(self, flag=BOTH, pairs_fn=PAIRS, ratings_fn=RATINGS):
    self.pairs_fn = pairs_fn
    self.ratings_fn = ratings_fn
    self.flag = flag
  def iterMovieIDsUserIDsRatings(self):
    pairs = file(self.pairs_fn)
    ratings = file(self.ratings_fn)
    mid = None
    for line in pairs:
      if line.strip() == "":
        assert(ratings.readline().strip() == "")
        return
      if ":" in line:
        mid = int(line.strip().strip(":"))
        assert(mid == int(ratings.readline().strip().strip(":")))
      else:
        s_uid, date = line.strip().split(",")
        uid = int(s_uid)
        r, flag = map(int, ratings.readline().strip().split(","))
        if self.flag == flag or self.flag == BOTH:
          yield mid, uid, r
        